package org.rand;

import java.util.Random;

public class RandDemo {
    public static void main(String[] args) {
        //随机1
        double d1 = Math.random(); //随机0-1 之间的小数
        System.out.println(d1);

        Random rand = new Random();
        boolean b = rand.nextBoolean();//随机true false
        System.out.println(b);
        double d2 = rand.nextDouble();//随机0-1 之间的小数
        System.out.println(d2);
        int i = rand.nextInt();//随机整数
        System.out.println(i);

        //1-5 1 2 3 4 5 随机数
        System.out.println(rand.nextInt(1, 6));


        System.out.println();
        //随机10-20
        for (int i1 = 0; i1 < 10; i1++) {
            System.out.printf("%d \t", rand.nextInt(10, 21));
        }

        System.out.println();
        //中奖30%
        int num = rand.nextInt(1, 101);
        if (num <= 30) {
            System.out.println("中奖");
        } else {
            System.out.println("未中奖");
        }

        //随机抽一个学生
        String[] sts = {"张三", "李四", "张三丰", "赵强", "郑三"}; //0 1 2 3 4
        int ok = rand.nextInt(sts.length);//0-4
        System.out.println(sts[ok]);


    }
}
